{
LANG : PASCAL
PROB : runround
}

program RUNROUND;
const
  fi = 'runround.in';
  fo = 'runround.out';
var
  m : longint;

function rr(k : longint) : boolean;
var
  a : array[0..9] of byte;
  t, d : array[1..10] of shortint;
  i, j, s, l : longint;
begin
  rr := false;
  l := 0;
  fillchar(a, sizeof(a), 0);
  while k <> 0 do
  begin
    inc(l);
    t[l] := k mod 10;
    inc(a[t[l]]);
    if a[t[l]] > 1 then exit;
    if t[l] = 0 then exit;
    k := k div 10;
  end;
  for i := 1 to l do d[i] := t[l-i+1];
  i := d[1] mod l + 1;
  s := 1;
  d[1] := -1;
  while (i <> 1) or (s < l) do
  begin
    if d[i] = -1 then exit;
    j := (i + d[i] mod l - 1) mod l+1;
    d[i] := -1;
    i := j;
    inc(s);
  end;
  rr := true;
end;

procedure process;
begin
  while true do
  begin
    inc(m);
    if rr(m) then
    begin
      writeln(m);
      exit;
    end;
  end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  read(m);
  process;
  close(output);
  close(input);
end.